
package nuce.myClass;

import java.awt.Color;
import java.util.Random;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import nuce.bo.QuestionBO;
import nuce.bo.QuestionSet;
import nuce.entity.Question;

public class MyQuestion {
    private int countQuestion = 0;
    private QuestionSet q; //tap cau hoi gom 15 cau : 5 cau level 1, 5 cau level 2  va` 5 cau level 3
    private int[] AnsTrue; // vi tri cua cau hoi dung chua set gia tri; hom sau set gia tri cho no'
    private QuestionSet q1, q2, q3; // q1,2,3 = tap cac cau hoi level1 ,2,3

    public MyQuestion()
    {
        createQuestion();
    }
    
    public int getCountQuestion() {
        return countQuestion;
    }

    public void setCountQuestion(int countQuestion) {
        this.countQuestion = countQuestion;
    }

    public QuestionSet getQ1() {
        return q1;
    }

    public void setQ1(QuestionSet q1) {
        this.q1 = q1;
    }

    public QuestionSet getQ2() {
        return q2;
    }

    public void setQ2(QuestionSet q2) {
        this.q2 = q2;
    }

    public QuestionSet getQ3() {
        return q3;
    }

    public QuestionSet getQ() {
        return q;
    }

    public void setQ3(QuestionSet q3) {
        this.q3 = q3;
    }
    public boolean isAnwer(int i) //lam chuc nang kiem tra
    {
        // dang lam do dang muc nay
        //kiem tra xem o cau hoi thu i tra loi dung hay sai dua vao ban tham chieu cau hoi
        return false;
    }
     public void createQuestion() {  //dang gap van de o tham chieu
        q = new QuestionSet();
        countQuestion = 0;
        q1 = new QuestionSet();
        q2 = new QuestionSet();
        q3 = new QuestionSet();
        q1.SelectByLevel(1);
        q2.SelectByLevel(2);
        q3.SelectByLevel(3);
// Do du lieu vao q (15 cau hoi )
        int i = 0;
        int indextRandom;
        int count1;  //cout1  = so luong cau hoi level1, cout2 level2...

        Random rd = new Random();
        for (i = 0; i < 5; i++) {
            count1 = q1.getCount();
            if (count1 > 0) {
                indextRandom = rd.nextInt(count1);
                q.add(q1.getItem(indextRandom));
                q1.remove(indextRandom);
                count1--;
            } else {
                q.add(q1.getItem(0));
            }
        }
        for (i = 0; i < 5; i++) {
            if (q2.getCount() > 0) {
                indextRandom = rd.nextInt(q2.getCount());
                q.add(q2.getItem(indextRandom));
                q2.remove(indextRandom);
            } else {
                q.add(q2.getItem(1));
            }
        }
        for (i = 0; i < 5; i++) {
            if (q3.getCount() > 0) {
                indextRandom = rd.nextInt(q3.getCount());
                q.add(q3.getItem(indextRandom));
                q3.remove(indextRandom);
            } else {
                q.add(q2.getItem(0));
            }
        }
        randomAnwer();
    }
    public void changeLabel(JLabel lb){
        Border b = new LineBorder(Color.RED);
        lb.setBorder(b);
    }

     
     // Random dap an dung, dap an dung ko nam o dap an A nua!!!!
    public void randomAnwer() {//chua dung den
        int i, indexRandom=1;
        int n = q.getCount();
        Random rd = new Random();
        //indexRandom = rd.nextInt(4)+1;
        AnsTrue = new int[n];
        QuestionBO qb = new QuestionBO();
        Question qtemp = new Question();
                
        for (i=0; i<n; i++){
            qtemp = q.getItem(i);
            qb.swap(qtemp, 1, indexRandom);
            q.updateItem(i,qtemp);  //da sua
            AnsTrue[i] = indexRandom;
        }
    }
    public static void main(String[]args)
    {
        MyQuestion m = new MyQuestion();
        Vidu v = new Vidu(3,4);
        //m.swap(v);
        v.show();
    }
    public void swap(Vidu a)
    {
        a.setA(1);
    }
}

class Vidu{
    private int a, b;
    
    public void setA(int a){
        this.a= a;
    }
    public void setB(int b){
        this.b = b;
    }
    Vidu(int a, int b){
        this.a = a; this.b = b;
    }
    public void show(){
        System.out.println("a = "+a+"  b= "+b);
    }
}